package com.tozed.android.launcher;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tozed.android.launcher.R;

public class DeleteDropZoneView extends LinearLayout {

    private Paint textPaintStraight;
    private Paint textPaintRed;
    private Paint bitmapPaint;
    private Paint bitmapPaintRed;
    private boolean straight = true;

    private Bitmap trash;
    private Rect bounds;

    private final int mTransitionDuration;
    private int mBottomDragPadding;
    private TransitionDrawable mCurrentDrawable;
    protected int mHoverColor = 0;
    TextView mText;

    public DeleteDropZoneView(Context context) {
        this(context, null);
    }
    public DeleteDropZoneView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }
    public DeleteDropZoneView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        Resources r = getResources();
        mTransitionDuration = r.getInteger(R.integer.config_dropTargetBgTransitionDuration);
        mBottomDragPadding = r.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
        mHoverColor = r.getColor(R.color.delete_target_hover_tint);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mText = (TextView) findViewById(R.id.delete_target_text);
    }

    @Override
    public void getHitRect(android.graphics.Rect outRect) {
        super.getHitRect(outRect);
        outRect.bottom += mBottomDragPadding;
    }

    protected Drawable getCurrentDrawable() {
        Drawable[] drawables = mText.getCompoundDrawablesRelative();
        for (int i = 0; i < drawables.length; ++i) {
            if (drawables[i] != null) {
                return drawables[i];
            }
        }
        return null;
    }

    public void highlight() {
        mCurrentDrawable = (TransitionDrawable) getCurrentDrawable();
        mCurrentDrawable.startTransition(mTransitionDuration);
        mText.setTextColor(mHoverColor);
        this.setSelected(true);
    }

    public void smother() {
        mCurrentDrawable = (TransitionDrawable) getCurrentDrawable();
        mCurrentDrawable.resetTransition();
        mText.setTextColor(Color.WHITE);
        this.setSelected(false);
    }
}
